<template>
  <div class="all">
    <h4>资产监控</h4>
    <el-row :gutter="20" class="bigbox">
      <el-col :span="6" class="box" style="padding: 0px">
        <div class="left1">
          <img src="../assets/images/个人.svg" />
        </div>
        <div class="right1">
          <h5>设备总量</h5>
          <span>{{ facilityAmount }}</span>
        </div>
      </el-col>
      <el-col :span="6" class="box" style="padding: 0px">
        <div class="left1">
          <img src="../assets/images/铃铛.svg" />
        </div>
        <div class="right1">
          <h5>资产总额</h5>
          <span>{{ allMoney }}</span>
        </div>
      </el-col>
      <el-col :span="6" class="box" style="padding: 0px">
        <div class="left1">
          <img src="../assets/images/眼睛.svg" />
        </div>
        <div class="right1">
          <h5>借出数量</h5>
          <span>{{ borrow }}</span>
        </div>
      </el-col>
      <el-col :span="6" class="box" style="padding: 0px">
        <div class="left1">
          <img src="../assets/images/点赞.svg" />
        </div>
        <div class="right1">
          <h5>丢失数量</h5>
          <span>{{ borrow }}</span>
        </div>
      </el-col>
    </el-row>
    <h4>资产统计</h4>
    <div
      class="echart"
      id="mychart"
      :style="{ float: 'left', width: '100%', height: '400px' }"
    ></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import server from "../serive/home";

export default {
  data() {
    return {
      list: [],
      list1: [],
      // maintainExpend:maintainExpend,
    };
  },
  mounted() {},
  computed: {
    facilityAmount() {
      var num1 = 0;
      for (let i in this.list) {
        num1 = num1 + parseInt(this.list[i].facilityAmount);
      }
      // console.log(num1);
      return num1;
    },
    allMoney() {
      var num = 0;
      for (let i in this.list) {
        num =
          num +
          parseInt(this.list[i].facilityAmount * this.list[i].facilityPrice);
      }
      return num;
    },
    borrow() {
      var num = 0;
      for (let i in this.list) {
        num = num + Number(this.list[i].leaseNum);
      }
      return num;
    },
    lose() {
      var num = 0;
      for (let i in this.list) {
        num = num + Number(this.list[i].loseNum);
      }
      return num;
    },
    maintainExpend() {
      var num = 0;
      for (let i in this.list) {
        num = num + Number(this.list[i].maintainExpend);
      }
      return num;
    },
  },
  methods: {
    loadRid() {
      var rid = localStorage.getItem("rid");
      this.rid = rid;
    },
    initEcharts() {
      const option = {
        tooltip: {},
        legend: {
          data: ["总量"],
        },
        xAxis: {
          data: ["维修费用", "报修数量", "归还数量", "报废数量"],
        },
        yAxis: {},
        series: [
          {
            name: "",
            type: "bar", //类型为柱状图
            data: this.list1,
            itemStyle: {
              normal: {
                //这里是颜色
                color: function (params) {
                  //注意，如果颜色太少的话，后面颜色不会自动循环，最好多定义几个颜色
                  var colorList = ["#6F4F4A", "#F19372","#6F4F4A", "#F19372"];
                  return colorList[params.dataIndex];
                },
              },
            },
          },
        ],
      };
      const myChart = echarts.init(document.getElementById("mychart")); // 图标初始化
      myChart.setOption(option); // 渲染页面
      //随着屏幕大小调节图表
      window.addEventListener("resize", () => {
        myChart.resize();
      });
    },
    pushList() {
      var num1 = 0;
      var num2 = 0;
      var num3 = 0;
      var num4 = 0;
      console.log("list", this.list);
      server.getHome().then((res) => {
        // var repairsNum=0;
        this.list = res.data.data;
        for (let i in this.list) {
          num1 = num1 + Number(this.list[i].maintainExpend);
          num2 = num2 + Number(this.list[i].repairsNum);
          num3 = num3 + Number(this.list[i].returnNum);
          num4 = num4 + Number(this.list[i].scrapNum);
          // console.log("", this.list[i].repairsNum);
        }
        console.log(this.list);
        // console.log(this.list1);
        // console.log(num1, num2);
        this.list1.push(num1, num2, num3, num4);
        console.log(this.list1);
        this.initEcharts();
      });
    },
  },

  created() {
    this.loadRid();
    this.pushList();
  },
};
</script>
<style  >
.box {
  display: flex;
  padding: 0px;
  justify-content: center;
  align-items: center;
}
.bigbox {
  margin-top: 15px;
  background: white;
  height: 150px;
  display: flex;
  border-radius: 30px;
  box-shadow: rgba(165, 165, 165, 0.267) 3px 3px 3px 3px;
}
h4 {
  margin-top: 30px;
}
.message {
  height: 100%;
  box-shadow: rgba(165, 165, 165, 0.267) 3px 3px 3px 3px;
  border-radius: 10px;
  background: white;
  margin-top: 15px;
}
.left1 {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px pink solid;
  width: 70px;
  height: 70px;
  border-radius: 10px;
}
.left1 > img {
  width: 40px;
}
.right1 {
  padding-left: 40px;
}
.right1 > span {
  font-size: 36px;
  color: #343961;
}
.right1 > h5 {
  color: rgb(210, 210, 211);
}
h4 {
  color: #343961;
}
.echart {
  margin-top: 15px;
  background: white;
  box-shadow: rgba(165, 165, 165, 0.267) 3px 3px 3px 3px;
  border-radius: 30px;
}
</style>